<html>
<head><meta charset="utf-8"><title>hir::DefId to HirId or LocalDefId · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/hir.3A.3ADefId.20to.20HirId.20or.20LocalDefId.html">hir::DefId to HirId or LocalDefId</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213786062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/hir%3A%3ADefId%20to%20HirId%20or%20LocalDefId/near/213786062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BN <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/hir.3A.3ADefId.20to.20HirId.20or.20LocalDefId.html#213786062">(Oct 19 2020 at 13:38)</a>:</h4>
<p>Given a TraitRef I would like to get access to the DefIds of the associated items of the trait. I think I can do this using  the item method of the HIR map and later use the TraitItemRefs slice of the trait item. The item method requires a HirId and there is a method to convert a LocalDefId to HirId, but I can't find a way to convert the DefId into an HirId or LocalDefId. Can anybody please tell me whether this is possible and, if so, how to do it?</p>



<a name="213786140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/hir%3A%3ADefId%20to%20HirId%20or%20LocalDefId/near/213786140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/hir.3A.3ADefId.20to.20HirId.20or.20LocalDefId.html#213786140">(Oct 19 2020 at 13:38)</a>:</h4>
<p><code>DefId</code> -&gt; <code>LocalDefId</code>: <code>def_id.expect_local()</code> or <code>def_id.as_local()</code></p>



<a name="213786237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/hir%3A%3ADefId%20to%20HirId%20or%20LocalDefId/near/213786237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/hir.3A.3ADefId.20to.20HirId.20or.20LocalDefId.html#213786237">(Oct 19 2020 at 13:39)</a>:</h4>
<p><code>DefId</code> -&gt; <code>HirId</code>: <code>DefId</code> -&gt; <code>LocalDefId</code> -&gt; <code>HirId</code></p>



<a name="213786347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/hir%3A%3ADefId%20to%20HirId%20or%20LocalDefId/near/213786347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/hir.3A.3ADefId.20to.20HirId.20or.20LocalDefId.html#213786347">(Oct 19 2020 at 13:40)</a>:</h4>
<p><code>LocalDefId</code> -&gt; <code>HirId</code>: <code>tcx.hir().local_def_id_to_hir_id(local_def_id)</code> or <code>tcx.hir().opt_local_def_id_to_hir_id(local_def_id)</code></p>



<a name="213787101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/hir%3A%3ADefId%20to%20HirId%20or%20LocalDefId/near/213787101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BN <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/hir.3A.3ADefId.20to.20HirId.20or.20LocalDefId.html#213787101">(Oct 19 2020 at 13:45)</a>:</h4>
<p>Thanks a lot. I was looking at the <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefId.html">docs</a> and the only information provided there is how to get a DefId from a LocalDefId. Would it be possible to add information about conversions from DefId to the docs?</p>



<a name="213787494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/hir%3A%3ADefId%20to%20HirId%20or%20LocalDefId/near/213787494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/hir.3A.3ADefId.20to.20HirId.20or.20LocalDefId.html#213787494">(Oct 19 2020 at 13:48)</a>:</h4>
<p>yeah, want to open a PR for that and assign me as the reviewer?</p>



<a name="213788786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/hir%3A%3ADefId%20to%20HirId%20or%20LocalDefId/near/213788786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BN <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/hir.3A.3ADefId.20to.20HirId.20or.20LocalDefId.html#213788786">(Oct 19 2020 at 13:57)</a>:</h4>
<p>Yes I will do that</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>